package router

import (
	"frontend-server/controller"
	"frontend-server/middleware"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.Default()
	v1 := r.Group("/api/v1")
	{
		auth := v1.Group("/auth")
		{
			auth.POST("/login", controller.AuthController{}.Login)       // 用户登录
			auth.POST("/register", controller.AuthController{}.Register) // 用户注册
			auth.GET("/send_code", controller.AuthController{}.SendCode) // 发送验证码
		}
		user := v1.Group("/user", middleware.JWTAuthMiddleware())
		{
			user.GET("/userinfo", controller.UserController{}.UserInfo)               // 用户信息
			user.POST("/modify_userinfo", controller.UserController{}.ModifyUserInfo) // 修改用户信息
			user.POST("/modify_password", controller.UserController{}.ModifyPassword) // 修改用户密码
			user.POST("/upload_avatar")                                               // 修改用户头像
		}
		ws := v1.Group("/websocket", middleware.JWTAuthMiddleware())
		{
			ws.GET("/init", controller.WebsocketController{}.Init) // 初始化 ws
			chat := ws.Group("/chat")                              // 聊天
			{
				chat.GET("/list", controller.ChatController{}.ChatList) // 聊天记录列表
			}
			addressbook := ws.Group("/addressbook") // 通讯录
			{
				addressbook.GET("/page_friend", controller.AddressbookController{}.Pagefriend)  //查询用户好友列表
				addressbook.POST("/add_friend", controller.AddressbookController{}.AddFriend)   // 添加好友
				addressbook.POST("/friend_info", controller.AddressbookController{}.FriendInfo) // 查询好友资料
				addressbook.POST("/del_friend", controller.AddressbookController{}.DelFriend)   // 删除好友
				addressbook.GET("/page_group", controller.AddressbookController{}.PageGroup)    // 查询用户群列表
				addressbook.POST("/add_group", controller.AddressbookController{}.AddGroup)     // 创建群聊
				addressbook.POST("/del_group", controller.AddressbookController{}.DelGroup)     // 删除群聊
			}
		}
	}
	return r
}
